/*
 * ConfigFactory.java
 *
 * Created on 20 July 2007, 11:28
 *
 * Copyright (C)
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */

package com.grubby.databean.utils;

import java.io.File;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

/**
 * Processor to process commnand line arguments and files in the resource 
 * bundle.
 * @author A. HARMEL-LAW. E: andrew.harmel.law@gmail.com
 * @version 0.1
 */
public class ConfigFactory {
    
    // TODO Process this.
    
    /** The config object holding the processed application configuration. */
    private static Config config;
    
    /** The config object holding the processed ldap configuration. */
    private static Map ldapConfig;
    
//    /** The resource bundle for the application. */
//    private final static PropertyResourceBundle appConfigBundle
//            = (PropertyResourceBundle) ResourceBundle.getBundle(
//            ApplicationConstants.CONFIG_RESOURCE_BUNDLE_NAME,
//            ApplicationConstants.APPLICATION_LOCAL);
    
//    /** The resource bundle for the application. */
//    private final static PropertyResourceBundle ldapConfigBundle
//            = (PropertyResourceBundle) ResourceBundle.getBundle(
//            ApplicationConstants.LDAP_CONFIG_RESOURCE_FILE,
//            ApplicationConstants.APPLICATION_LOCAL);
    
    public static Config getApplicationConfig() {
        if (config == null) {
            throw new RuntimeException("Config object has not been created "
                    + "yet, please call createConfig first");
        }
        return ConfigFactory.config;
    }
    
//    /**
//     * Method to process the command line argunments and the resource bundle
//     * used by the application.
//     * @param args command line arguments passed through from the
//     * Main.start(args) class
//     */
//    public static Config createConfig(String[] args) {
//        
//        if (ConfigFactory.config != null) {
//            throw new IllegalArgumentException("Configuration for this "
//                    + "application has already been created, please call "
//                    + "getConfig()");
//        }
//        
//        //Process command line arguments and resource bundle
//        ConfigFactory.config = new Config(
//                Arrays.asList(appConfigBundle.getString(
//                ApplicationConstants.RESOURCE_BUNDLE_PROPERTY_IMPORTABLE_NODES)
//                .split(",")),
//                appConfigBundle.getString(
//                ApplicationConstants.RESOURCE_BUNDLE_PROPERTY_LDAP_SUFFIX),
//                new File(args[1] + "/" + args[2]),
//                new File(args[1]),
//                (new Boolean(appConfigBundle.getString(
//                ApplicationConstants.RESOURCE_BUNDLE_PROPERTY_PERFORM_DATA_MASSAGING))).booleanValue()
//                );
//        
//        return config;
//        
//    }
    
//    /** Get the ldap properties from the file. */
//    public static Map getLdapConfig() {
//        
//        if (ldapConfig == null) {
//            ldapConfig = new HashMap();
//            Enumeration keys = ldapConfigBundle.getKeys();
//            while (keys.hasMoreElements()) {
//                String key = (String) keys.nextElement();
//                ldapConfig.put(key, ldapConfigBundle.getString(key));
//            }
//        }
//        return ldapConfig;
//    }
    
}
